<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true" style="position: unset;height: unset;">
      <el-form-item :label="$t('项目企业名称')" prop="projectName" style="margin-bottom: 10px;">
        <el-input
          v-model="queryParams.projectName"
          size="small"
          :placeholder="$t('项目企业名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item style="margin-bottom: 10px;">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-if="!btnHide && processBtn" v-hasPermi="['fund:monitor:edit']" type="primary" icon="el-icon-plus" size="mini" @click="addHandle({})">{{ $t("新增") }}</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="form.dataList" border class="nowrapTable formTable">
      <!--      <el-table-column type="index" align="center" show-overflow-tooltip width="50">-->
      <!--        <template slot-scope="scope">-->
      <!--          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column :label="$t('序号')" align="center" prop="num" min-width="50" />
      <el-table-column :label="$t('项目企业名称')" align="center" prop="projectName" min-width="210">
        <template slot-scope="scope">
          <el-link class="link-a" type="primary" @click="addHandle(scope.row)">{{ scope.row.projectName }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否海外投资')" align="center" prop="overseasInvest" min-width="150">
        <template slot-scope="scope">
          {{ scope.row.overseasInvest }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目企业统一社会信用编码')" align="center" prop="creditCode" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.creditCode }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目企业成立日期')" align="center" prop="projectCompanyEstablishDate" min-width="150">
        <template slot-scope="scope">
          {{ parseTime(scope.row.projectCompanyEstablishDate) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目企业注册地')" align="center" prop="registration" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.registration }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目企业股票代码')" align="center" prop="stockCode" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.stockCode }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('投资行业')" align="center" prop="investIndustry" min-width="150">
        <template slot-scope="scope">
          {{ scope.row.investIndustry }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('投资阶段')" align="center" prop="investStage" min-width="150">
        <template slot-scope="scope">
          {{ scope.row.investStage }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目投资账面价值')" align="center" prop="projectInvestBookValue" min-width="210">
        <template slot-scope="scope">
          {{ moneyFormat(scope.row.projectInvestBookValue) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('其中：股权投资账面价值')" align="center" prop="equityInvestBookValue" min-width="210">
        <template slot-scope="scope">
          {{ moneyFormat(scope.row.equityInvestBookValue) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('股权投资估值方法')" align="center" prop="equityInvestValuationMethod" min-width="210">
        <template slot-scope="scope">
          {{ moneyFormat(scope.row.equityInvestValuationMethod) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('占被投资单位股权比重')" align="center" prop="investEquityProportion" min-width="210">
        <template slot-scope="scope">
          {{ moneyFormat(scope.row.investEquityProportion) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('其中：债权投资账面价值')" align="center" prop="bondInvestBookValue" min-width="210">
        <template slot-scope="scope">
          {{ moneyFormat(scope.row.bondInvestBookValue) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('债权投资估值方法')" align="center" prop="bondInvestValuationMethod" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.bondInvestValuationMethod }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目投资日期及投资本金')" align="center" prop="projectInvestDateAndPrincipal" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.projectInvestDateAndPrincipal }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('其中：股权投资日期、投资本金及标的来源')" align="center" prop="projectInvestDateAndPrincipalSource" min-width="250">
        <template slot-scope="scope">
          {{ scope.row.projectInvestDateAndPrincipalSource }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('其中：债权投资日期、投资本金、标的来源及债权类别')" align="center" prop="investType" min-width="300">
        <template slot-scope="scope">
          {{ scope.row.investType }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('退出情况')" align="center" prop="exitSituation" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.exitSituation }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('退出信息')" align="center" prop="exitInfo" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.exitInfo }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否属于中小企业')" align="center" prop="smes" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.smes }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否属于高新技术企业')" align="center" prop="highTechEnterprises" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.highTechEnterprises }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否属于初创科技型企业')" align="center" prop="startUpTechnologyCompanies" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.startUpTechnologyCompanies }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否享受国家财税政策')" align="center" prop="nationalFiscalPolicy" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.nationalFiscalPolicy }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('投资风控基本情况')" align="center" prop="investRiskControl" min-width="210">
        <template slot-scope="scope">
          {{ scope.row.investRiskControl }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目所属行业景气程度较去年同期')" align="center" prop="industryBoom" min-width="250">
        <template slot-scope="scope">
          {{ scope.row.industryBoom }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理人认为项目公司当前的主要机遇')" align="center" prop="mainOpportunity" min-width="250">
        <template slot-scope="scope">
          {{ scope.row.mainOpportunity }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理人认为项目公司当前的主要风险')" align="center" prop="mainRisk" min-width="250">
        <template slot-scope="scope">
          {{ scope.row.mainRisk }}
        </template>
      </el-table-column>
      <el-table-column v-if="processBtn" :label="$t('操作')" align="center" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button v-if="!btnHide" size="mini" type="text" icon="el-icon-edit" @click="addHandle(scope.row)">{{ $t('编辑') }}</el-button>
          <el-button v-if="!btnHide" size="mini" type="text" icon="el-icon-delete" @click="delHandle(scope.row)">{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList({ id: parentMonitorId, fundId: parenFundId })"
    />

    <!-- 项目情况对话框 -->
    <el-dialog :title="$t('项目情况')" :visible.sync="formOpen" width="50%" :close-on-click-modal="false" :lock-scroll="false" append-to-body custom-class="dialogForm">
      <fundProjectStatusForm ref="fundProjectStatusForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listFundProjectStatus, batchSave, getDefaultData, delFundProjectStatus } from '@/api/fund/operation/fundProjectStatus'
import fundProjectStatusForm from '@/views/fund/operation/fundProjectStatusForm.vue'
export default {
  components: {
    fundProjectStatusForm
  },
  data() {
    return {
      // 总条数
      total: 0,
      // 表单参数
      form: {
        monitorId: undefined,
        dataList: []
      },
      // 遮罩层
      loading: false,
      // 表单校验
      rules: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: undefined,
        monitorId: undefined,
        orderByColumn: 'a.num'
      },
      parentMonitorId: '',
      parenFundId: '',
      formOpen: false,
      processBtn: true,
      btnHide: false,
      monitorData: {}
    }
  },
  created() {
  },
  methods: {
    init(data) {
      this.processBtn = data.processBtn
      this.parentMonitorId = data.id
      this.parenFundId = data.fundId
      this.getList(data)
      this.monitorData = data
    },
    // 初始化数据
    getList(data) {
      this.loading = true
      this.btnHide = data.btnHide
      if (data.id !== undefined) {
        this.form.monitorId = data.id
        this.queryParams.monitorId = data.id
        listFundProjectStatus(this.queryParams).then(response => {
          this.form.dataList = response.rows
          this.total = response.total
          // 若果为空. 则表示可能是新建的主表数据 , 默认带出来这个基金的投资主体
          if (response.rows === null || response.rows.length === 0) {
            getDefaultData(data.fundId, data.id).then(res => {
              this.form.dataList = res.rows
              this.total = res.total
              this.loading = false
            })
          } else {
            this.loading = false
          }
        })
      } else {
        this.reset()
        this.loading = false
      }
    },
    // 表单重置
    reset() {
      this.form = {
        monitorId: undefined,
        dataList: []
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.reset()
      this.$parent.$parent.$parent.$parent.indicatorFormOpen = false
      this.$emit('cancel', undefined)
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      if (this.$parent.$parent.$parent.$parent.indicatorFormOpen !== undefined) {
        this.$parent.$parent.$parent.$parent.indicatorFormOpen = false
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          batchSave(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      })
    },
    addHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        row.monitorId = this.form.monitorId
        row.processBtn = this.processBtn
        row.total = this.total
        row.btnHide = this.btnHide
        this.$refs.fundProjectStatusForm.init(row)
      })
    },
    delHandle(row) {
      var that = this
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      })
      .then(function() {
        delFundProjectStatus(row.id).then(res => {
          if (res.code === 200) {
            that.getList(that.monitorData)
            that.msgSuccess(that.$t('删除成功!'))
          }
        }).catch(() => {
          that.errorMsg(that.$t('删除失败!'))
        })
      }).then(() => {
      })
    },
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList({ id: this.parentMonitorId, fundId: this.parenFundId })
    },
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    }
  }
}
</script>
